<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - id:000977,sync:fuzzer2,src:001052.lcov_info_final - src/regeximpl.h</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - regeximpl.h<span style="font-size: 80%;"> (source / <a href="regeximpl.h.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">id:000977,sync:fuzzer2,src:001052.lcov_info_final</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">73</td>
            <td class="headerCovTableEntry">75</td>
            <td class="headerCovTableEntryHi">97.3 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2016-03-13 10:42:47</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">25</td>
            <td class="headerCovTableEntry">26</td>
            <td class="headerCovTableEntryHi">96.2 %</td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #ifndef REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66</a>
<span class="lineNum">       2 </span>            : #define REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
<span class="lineNum">       3 </span>            : 
<span class="lineNum">       4 </span>            : #if defined(_MSC_VER) ||                                            \
<span class="lineNum">       5 </span>            :     (defined(__GNUC__) &amp;&amp; (__GNUC__ == 3 &amp;&amp; __GNUC_MINOR__ &gt;= 4) || \
<span class="lineNum">       6 </span>            :      (__GNUC__ &gt;= 4))  // GCC supports &quot;pragma once&quot; correctly since 3.4
<span class="lineNum">       7 </span>            : #pragma once
<span class="lineNum">       8 </span>            : #endif
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : #include &quot;stream.h&quot;
<span class="lineNum">      11 </span>            : #include &quot;stringsource.h&quot;
<span class="lineNum">      12 </span>            : #include &quot;streamcharsource.h&quot;
<span class="lineNum">      13 </span>            : 
<a name="14"><span class="lineNum">      14 </span>            : namespace YAML {</a>
<span class="lineNum">      15 </span>            : // query matches
<span class="lineNum">      16 </span><span class="lineCov">         40 : inline bool RegEx::Matches(char ch) const {</span>
<span class="lineNum">      17 </span><span class="lineCov">         80 :   std::string str;</span>
<span class="lineNum">      18 </span><span class="lineCov">         40 :   str += ch;</span>
<span class="lineNum">      19 </span><span class="lineCov">         80 :   return Matches(str);</span>
<a name="20"><span class="lineNum">      20 </span>            : }</a>
<span class="lineNum">      21 </span>            : 
<span class="lineNum">      22 </span><span class="lineCov">      10655 : inline bool RegEx::Matches(const std::string&amp; str) const {</span>
<span class="lineNum">      23 </span><span class="lineCov">      10655 :   return Match(str) &gt;= 0;</span>
<a name="24"><span class="lineNum">      24 </span>            : }</a>
<span class="lineNum">      25 </span>            : 
<span class="lineNum">      26 </span><span class="lineCov">    4009790 : inline bool RegEx::Matches(const Stream&amp; in) const { return Match(in) &gt;= 0; }</span>
<a name="27"><span class="lineNum">      27 </span>            : </a>
<span class="lineNum">      28 </span>            : template &lt;typename Source&gt;
<span class="lineNum">      29 </span><span class="lineCov">     220691 : inline bool RegEx::Matches(const Source&amp; source) const {</span>
<span class="lineNum">      30 </span><span class="lineCov">     220691 :   return Match(source) &gt;= 0;</span>
<span class="lineNum">      31 </span>            : }
<span class="lineNum">      32 </span>            : 
<span class="lineNum">      33 </span>            : // Match
<span class="lineNum">      34 </span>            : // . Matches the given string against this regular expression.
<span class="lineNum">      35 </span>            : // . Returns the number of characters matched.
<span class="lineNum">      36 </span>            : // . Returns -1 if no characters were matched (the reason for
<span class="lineNum">      37 </span>            : //   not returning zero is that we may have an empty regex
<a name="38"><span class="lineNum">      38 </span>            : //   which is ALWAYS successful at matching zero characters).</a>
<span class="lineNum">      39 </span>            : // . REMEMBER that we only match from the start of the buffer!
<span class="lineNum">      40 </span><span class="lineCov">      10655 : inline int RegEx::Match(const std::string&amp; str) const {</span>
<span class="lineNum">      41 </span><span class="lineCov">      10655 :   StringCharSource source(str.c_str(), str.size());</span>
<span class="lineNum">      42 </span><span class="lineCov">      10655 :   return Match(source);</span>
<a name="43"><span class="lineNum">      43 </span>            : }</a>
<span class="lineNum">      44 </span>            : 
<span class="lineNum">      45 </span><span class="lineCov">    4139795 : inline int RegEx::Match(const Stream&amp; in) const {</span>
<span class="lineNum">      46 </span><span class="lineCov">    8279590 :   StreamCharSource source(in);</span>
<span class="lineNum">      47 </span><span class="lineCov">    8279590 :   return Match(source);</span>
<span class="lineNum">      48 </span>            : }
<a name="49"><span class="lineNum">      49 </span>            : </a>
<span class="lineNum">      50 </span>            : template &lt;typename Source&gt;
<span class="lineNum">      51 </span><span class="lineCov">    9452955 : inline bool RegEx::IsValidSource(const Source&amp; source) const {</span>
<span class="lineNum">      52 </span><span class="lineCov">    9452955 :   return source;</span>
<span class="lineNum">      53 </span>            : }
<a name="54"><span class="lineNum">      54 </span>            : </a>
<span class="lineNum">      55 </span>            : template &lt;&gt;
<span class="lineNum">      56 </span><span class="lineCov">    1604316 : inline bool RegEx::IsValidSource&lt;StringCharSource&gt;(</span>
<span class="lineNum">      57 </span>            :     const StringCharSource&amp; source) const {
<span class="lineNum">      58 </span><span class="lineCov">    1604316 :   switch (m_op) {</span>
<span class="lineNum">      59 </span>            :     case REGEX_MATCH:
<span class="lineNum">      60 </span>            :     case REGEX_RANGE:
<span class="lineNum">      61 </span><span class="lineCov">    1110618 :       return source;</span>
<span class="lineNum">      62 </span>            :     default:
<span class="lineNum">      63 </span><span class="lineCov">     493698 :       return true;</span>
<span class="lineNum">      64 </span>            :   }
<span class="lineNum">      65 </span>            : }
<a name="66"><span class="lineNum">      66 </span>            : </a>
<span class="lineNum">      67 </span>            : template &lt;typename Source&gt;
<span class="lineNum">      68 </span><span class="lineCov">   11057271 : inline int RegEx::Match(const Source&amp; source) const {</span>
<span class="lineNum">      69 </span><span class="lineCov">   11057271 :   return IsValidSource(source) ? MatchUnchecked(source) : -1;</span>
<span class="lineNum">      70 </span>            : }
<a name="71"><span class="lineNum">      71 </span>            : </a>
<span class="lineNum">      72 </span>            : template &lt;typename Source&gt;
<span class="lineNum">      73 </span><span class="lineCov">   37849278 : inline int RegEx::MatchUnchecked(const Source&amp; source) const {</span>
<span class="lineNum">      74 </span><span class="lineCov">   37849278 :   switch (m_op) {</span>
<span class="lineNum">      75 </span>            :     case REGEX_EMPTY:
<span class="lineNum">      76 </span><span class="lineCov">      54481 :       return MatchOpEmpty(source);</span>
<span class="lineNum">      77 </span>            :     case REGEX_MATCH:
<span class="lineNum">      78 </span><span class="lineCov">   18799755 :       return MatchOpMatch(source);</span>
<span class="lineNum">      79 </span>            :     case REGEX_RANGE:
<span class="lineNum">      80 </span><span class="lineCov">     379030 :       return MatchOpRange(source);</span>
<span class="lineNum">      81 </span>            :     case REGEX_OR:
<span class="lineNum">      82 </span><span class="lineCov">   12042853 :       return MatchOpOr(source);</span>
<span class="lineNum">      83 </span>            :     case REGEX_AND:
<span class="lineNum">      84 </span><span class="lineCov">       7021 :       return MatchOpAnd(source);</span>
<span class="lineNum">      85 </span>            :     case REGEX_NOT:
<span class="lineNum">      86 </span><span class="lineCov">      87307 :       return MatchOpNot(source);</span>
<span class="lineNum">      87 </span>            :     case REGEX_SEQ:
<span class="lineNum">      88 </span><span class="lineCov">    6478831 :       return MatchOpSeq(source);</span>
<span class="lineNum">      89 </span>            :   }
<span class="lineNum">      90 </span>            : 
<span class="lineNum">      91 </span><span class="lineNoCov">          0 :   return -1;</span>
<span class="lineNum">      92 </span>            : }
<span class="lineNum">      93 </span>            : 
<span class="lineNum">      94 </span>            : //////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      95 </span>            : // Operators
<span class="lineNum">      96 </span>            : // Note: the convention MatchOp*&lt;Source&gt; is that we can assume
<span class="lineNum">      97 </span>            : // IsSourceValid(source).
<span class="lineNum">      98 </span>            : //       So we do all our checks *before* we call these functions
<span class="lineNum">      99 </span>            : 
<a name="100"><span class="lineNum">     100 </span>            : // EmptyOperator</a>
<span class="lineNum">     101 </span>            : template &lt;typename Source&gt;
<span class="lineNum">     102 </span><span class="lineCov">      53731 : inline int RegEx::MatchOpEmpty(const Source&amp; source) const {</span>
<span class="lineNum">     103 </span><span class="lineCov">      53731 :   return source[0] == Stream::eof() ? 0 : -1;</span>
<span class="lineNum">     104 </span>            : }
<a name="105"><span class="lineNum">     105 </span>            : </a>
<span class="lineNum">     106 </span>            : template &lt;&gt;
<span class="lineNum">     107 </span><span class="lineCov">        750 : inline int RegEx::MatchOpEmpty&lt;StringCharSource&gt;(</span>
<span class="lineNum">     108 </span>            :     const StringCharSource&amp; source) const {
<span class="lineNum">     109 </span><span class="lineCov">        750 :   return !source</span>
<span class="lineNum">     110 </span>            :              ? 0
<span class="lineNum">     111 </span><span class="lineCov">        750 :              : -1;  // the empty regex only is successful on the empty string</span>
<span class="lineNum">     112 </span>            : }
<span class="lineNum">     113 </span>            : 
<a name="114"><span class="lineNum">     114 </span>            : // MatchOperator</a>
<span class="lineNum">     115 </span>            : template &lt;typename Source&gt;
<span class="lineNum">     116 </span><span class="lineCov">   18799755 : inline int RegEx::MatchOpMatch(const Source&amp; source) const {</span>
<span class="lineNum">     117 </span><span class="lineCov">   18799755 :   if (source[0] != m_a)</span>
<span class="lineNum">     118 </span><span class="lineCov">   18354725 :     return -1;</span>
<span class="lineNum">     119 </span><span class="lineCov">     445030 :   return 1;</span>
<span class="lineNum">     120 </span>            : }
<span class="lineNum">     121 </span>            : 
<a name="122"><span class="lineNum">     122 </span>            : // RangeOperator</a>
<span class="lineNum">     123 </span>            : template &lt;typename Source&gt;
<span class="lineNum">     124 </span><span class="lineCov">     379030 : inline int RegEx::MatchOpRange(const Source&amp; source) const {</span>
<span class="lineNum">     125 </span><span class="lineCov">     379030 :   if (m_a &gt; source[0] || m_z &lt; source[0])</span>
<span class="lineNum">     126 </span><span class="lineCov">     322865 :     return -1;</span>
<span class="lineNum">     127 </span><span class="lineCov">      56165 :   return 1;</span>
<span class="lineNum">     128 </span>            : }
<span class="lineNum">     129 </span>            : 
<a name="130"><span class="lineNum">     130 </span>            : // OrOperator</a>
<span class="lineNum">     131 </span>            : template &lt;typename Source&gt;
<span class="lineNum">     132 </span><span class="lineCov">   12042853 : inline int RegEx::MatchOpOr(const Source&amp; source) const {</span>
<span class="lineNum">     133 </span><span class="lineCov">   37830519 :   for (std::size_t i = 0; i &lt; m_params.size(); i++) {</span>
<span class="lineNum">     134 </span><span class="lineCov">   26696861 :     int n = m_params[i].MatchUnchecked(source);</span>
<span class="lineNum">     135 </span><span class="lineCov">   26696861 :     if (n &gt;= 0)</span>
<span class="lineNum">     136 </span><span class="lineCov">     909195 :       return n;</span>
<span class="lineNum">     137 </span>            :   }
<span class="lineNum">     138 </span><span class="lineCov">   11133658 :   return -1;</span>
<span class="lineNum">     139 </span>            : }
<span class="lineNum">     140 </span>            : 
<span class="lineNum">     141 </span>            : // AndOperator
<span class="lineNum">     142 </span>            : // Note: 'AND' is a little funny, since we may be required to match things
<span class="lineNum">     143 </span>            : //       of different lengths. If we find a match, we return the length of
<a name="144"><span class="lineNum">     144 </span>            : //       the FIRST entry on the list.</a>
<span class="lineNum">     145 </span>            : template &lt;typename Source&gt;
<span class="lineNum">     146 </span><span class="lineCov">       7021 : inline int RegEx::MatchOpAnd(const Source&amp; source) const {</span>
<span class="lineNum">     147 </span><span class="lineCov">       7021 :   int first = -1;</span>
<span class="lineNum">     148 </span><span class="lineCov">       8609 :   for (std::size_t i = 0; i &lt; m_params.size(); i++) {</span>
<span class="lineNum">     149 </span><span class="lineCov">       8045 :     int n = m_params[i].MatchUnchecked(source);</span>
<span class="lineNum">     150 </span><span class="lineCov">       8045 :     if (n == -1)</span>
<span class="lineNum">     151 </span><span class="lineCov">       6457 :       return -1;</span>
<span class="lineNum">     152 </span><span class="lineCov">       1588 :     if (i == 0)</span>
<span class="lineNum">     153 </span><span class="lineCov">       1024 :       first = n;</span>
<span class="lineNum">     154 </span>            :   }
<span class="lineNum">     155 </span><span class="lineCov">        564 :   return first;</span>
<span class="lineNum">     156 </span>            : }
<span class="lineNum">     157 </span>            : 
<a name="158"><span class="lineNum">     158 </span>            : // NotOperator</a>
<span class="lineNum">     159 </span>            : template &lt;typename Source&gt;
<span class="lineNum">     160 </span><span class="lineCov">      87307 : inline int RegEx::MatchOpNot(const Source&amp; source) const {</span>
<span class="lineNum">     161 </span><span class="lineCov">      87307 :   if (m_params.empty())</span>
<span class="lineNum">     162 </span><span class="lineNoCov">          0 :     return -1;</span>
<span class="lineNum">     163 </span><span class="lineCov">      87307 :   if (m_params[0].MatchUnchecked(source) &gt;= 0)</span>
<span class="lineNum">     164 </span><span class="lineCov">       6185 :     return -1;</span>
<span class="lineNum">     165 </span><span class="lineCov">      81122 :   return 1;</span>
<span class="lineNum">     166 </span>            : }
<span class="lineNum">     167 </span>            : 
<a name="168"><span class="lineNum">     168 </span>            : // SeqOperator</a>
<span class="lineNum">     169 </span>            : template &lt;typename Source&gt;
<span class="lineNum">     170 </span><span class="lineCov">    6478831 : inline int RegEx::MatchOpSeq(const Source&amp; source) const {</span>
<span class="lineNum">     171 </span><span class="lineCov">    6478831 :   int offset = 0;</span>
<span class="lineNum">     172 </span><span class="lineCov">    6746549 :   for (std::size_t i = 0; i &lt; m_params.size(); i++) {</span>
<span class="lineNum">     173 </span><span class="lineCov">    6656188 :     int n = m_params[i].Match(source + offset);  // note Match, not</span>
<span class="lineNum">     174 </span>            :                                                  // MatchUnchecked because we
<span class="lineNum">     175 </span>            :                                                  // need to check validity after
<span class="lineNum">     176 </span>            :                                                  // the offset
<span class="lineNum">     177 </span><span class="lineCov">    6656188 :     if (n == -1)</span>
<span class="lineNum">     178 </span><span class="lineCov">    6388470 :       return -1;</span>
<span class="lineNum">     179 </span><span class="lineCov">     267718 :     offset += n;</span>
<span class="lineNum">     180 </span>            :   }
<span class="lineNum">     181 </span>            : 
<span class="lineNum">     182 </span><span class="lineCov">      90361 :   return offset;</span>
<span class="lineNum">     183 </span>            : }
<span class="lineNum">     184 </span>            : }
<span class="lineNum">     185 </span>            : 
<span class="lineNum">     186 </span>            : #endif  // REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.11</a></td></tr>
  </table>
  <br>

</body>
</html>
